import { mapState, mapMutations } from 'vuex'

export default {
  data () {
    return {
      spuTableLoading: false
    }
  },
  computed: {
    ...mapState('commonComps/spuAssociatedModal', [
      'associatedRowList', 'showModal'
    ])
  },
  methods: {
    ...mapMutations('commonComps/spuAssociatedModal', [
      'ASSOCIATED_GOODS', 'CANCEL_GOODS', 'CHANGE_MODAL_SWITCH', 'CLEAR_GOODS', 'DESTORY_STATE'
    ]),
    /* 从map对象中获取所有对象，合成一个数组 */
    getListFromMapFn () {
      let values = this.associatedRowList.values()
      let rowList = []
      for (let item of values) {
        rowList.push(item)
      }
      return rowList
    },
    /* spu维度下，父组件表格删除时，当一个spu对应多个sku，删除一个spu，对应的sku都删除 */
    handleDeleteSpuRow (row, tableData, type) {
      tableData.forEach(value => {
        if (value.spuNo === row.spuNo) {
          this.CANCEL_GOODS({ row, type })
        }
      })
    },
  }
}
